/*
 * JaCoLiB
 * Copyright (C) 2008 Alessandro Serra
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

package it.gashale.jacolib.json.object;

import it.gashale.jacolib.json.*;

import java.io.IOException;

import org.json.JSONException;
import org.json.JSONObject;

public class UnknowObject implements SerializationObjectInterface {
	private String m_original_type;
	private String m_original_value;
	
	public UnknowObject(String type, String val) {
		m_original_type=type;
		m_original_value=val;
	}
	public UnknowObject(Object obj) {
		m_original_type=obj.getClass().getName();
		m_original_value=obj.toString();
	}
	public UnknowObject() {
		m_original_type=null;
		m_original_value=null;
	}
	public String toString() {
		return m_original_type+":"+m_original_value;
	}
	public void readObject(Serializer serializer, JSONObject jsonobj) throws JSONException, IOException, InternalError {
		m_original_type=jsonobj.getString("typename");
		m_original_value=jsonobj.getString("value-as-string");
	}
	public void writeObject(Serializer serializer, JSONObject jsonobj) throws JSONException, IOException {
		jsonobj.put("type", "object.unkown");
		jsonobj.put("typename", m_original_type);
		jsonobj.put("value-as-string", m_original_value);
	}
}
